<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label">时间段</label>
                            <div class="layui-input-inline" >
                                <input type="text" name="searchDateRange" id="searchDateRange" autocomplete="off"
                                       placeholder="请选择日期范围" class="layui-input" readonly="readonly">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="button" id="data-search-btn" class="layui-btn layui-btn-primary" lay-submit=""
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜索
                            </button>
                            <button type="reset" id="data-reset-btn" class="layui-btn layui-btn-primary" lay-submit=""
                                    lay-filter="data-reset-btn"><i class="layui-icon"></i> 重置
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script>
    layui.use(['form', 'table'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        let tableObj = table.render({
            elem: '#currentTableId',
            url: 'CreditsServlet?method=search',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {type: "checkbox", width: 80},
                {field: 'name', width: 120, title: '姓名'},
                {field: 'code', width: 120, title: '学号'},
                {field: 'grade', width: 120, title: '年级', sort: true},
                {field: 'college', width: 160, title: '院系',templet:'<div>{{d.college.name}}</div>'},
                {field: 'achieveTime', width: 160, title: '取得时间'},
                {field: 'score', width: 150, title: '分值', sort: true},
                {field: 'reason', title: '事由', width: 160},
                {field: 'enterMan', title: '录入人', width: 160},
                {field: 'enterTime', title: '录入时间', width: 160},
                {field: 'remark', title: '备注', width: 160}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });



        form.on('switch(modifystatus)', function(obj){
            console.log(obj);
            var param = obj.value;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加学分信息',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'addCredit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑学分信息',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: 'editCredit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }
        });


        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            let params = {
                page:{curr:1, limit: 10},
                where:data.field
            }
            tableObj.reload(params);
        });

        $('#data-reset-btn').click(function () {
            let params = {
                page:{curr:1, limit: 10},
                where:null
            }
            tableObj.reload(params);
        })

    });


    layui.use('laydate', function(){
        var laydate = layui.laydate;

        // 日期范围
        laydate.render({
            elem: '#searchDateRange',
            type: 'month',
            range: '~'
        });

    });

</script>